import tkinter as tk
from tkinter import messagebox
import cv2
import time
from matplotlib import pyplot as plt
import numpy as np
import wiringpi
from wiringpi import GPIO
from PIL import Image, ImageTk, ImageDraw, ImageFont, ImageChops
import serial
import os
import matplotlib.cm as cm
import numpy as np
import queue
import threading
from datetime import datetime

class ThermalImagingApp:
    
    # 用户变量定义
    matrix = [[10.17, 31.61, 29.02, 29.74, 29.31, 29.81, 30.69, 32.33, 32.62, 32.34, 31.34, 31.4, 30.06, 28.39, 27.56, 28.54, 29.18, 29.23, 29.2, 29.84, 31.53, 31.05, 31.09, 29.78, 30.81, 30.82, 30.08, 30.47, 32.36, 30.45, 32.6, 31.36], [31.02, 28.15, 27.82, 28.09, 28.56, 27.84, 30.12, 31.34, 32.9, 31.23, 31.13, 30.87, 28.93, 27.23, 28.27, 28.44, 30.3, 29.2, 30.74, 30.82, 31.98, 30.51, 30.99, 29.61, 31.2, 28.89, 29.05, 30.01, 31.42, 29.65, 31.62, 30.99], [29.17, 30.27, 27.94, 28.47, 29.13, 28.65, 28.71, 29.64, 31.84, 32.3, 29.41, 30.88, 29.22, 29.32, 29.13, 29.53, 31.19, 31.0, 31.12, 31.53, 30.88, 30.59, 29.74, 30.71, 30.1, 29.43, 28.77, 29.46, 30.25, 29.83, 30.66, 29.82], [30.43, 28.38, 27.8, 28.96, 28.56, 27.0, 28.65, 29.4, 31.66, 31.28, 29.65, 30.31, 29.69, 29.06, 29.34, 31.11, 31.45, 30.57, 30.48, 30.91, 31.41, 29.76, 30.18, 29.77, 29.97, 28.43, 28.03, 28.52, 30.27, 28.58, 30.47, 30.1], [29.86, 28.64, 28.47, 29.39, 28.2, 28.06, 28.45, 29.53, 30.62, 31.79, 29.52, 30.3, 30.77, 30.77, 30.35, 30.45, 30.25, 30.68, 31.25, 31.52, 31.52, 30.3, 29.21, 29.63, 28.9, 28.23, 27.96, 28.13, 29.43, 28.96, 29.04, 28.74], [28.76, 27.25, 27.49, 27.99, 27.83, 27.39, 28.26, 29.26, 30.78, 30.2, 29.73, 30.32, 31.58, 30.48, 30.02, 30.36, 31.37, 30.69, 32.33, 32.8, 32.08, 29.76, 29.02, 29.03, 29.11, 27.81, 27.68, 27.9, 28.82, 27.66, 27.75, 27.97], [28.76, 29.6, 27.52, 29.49, 29.03, 28.88, 28.88, 30.09, 30.92, 31.62, 30.81, 31.22, 30.9, 31.23, 31.26, 32.17, 33.27, 34.28, 33.53, 33.33, 30.5, 29.75, 28.61, 28.12, 28.66, 28.43, 28.05, 27.88, 27.69, 27.63, 28.13, 27.94], [29.41, 27.78, 27.24, 28.49, 28.93, 28.34, 29.08, 29.38, 30.95, 29.85, 30.18, 30.8, 31.99, 31.13, 32.66, 32.91, 34.37, 33.41, 33.17, 32.55, 29.46, 28.05, 27.8, 27.65, 28.42, 27.14, 26.44, 27.06, 28.16, 28.12, 27.94, 27.51], [28.91, 29.08, 27.99, 29.29, 29.16, 30.49, 30.07, 31.07, 31.11, 31.95, 30.97, 32.25, 33.55, 34.95, 34.86, 34.97, 33.16, 32.82, 30.7, 29.41, 27.5, 27.89, 26.92, 26.88, 27.67, 26.91, 27.11, 27.04, 28.13, 28.21, 27.17, 27.67], [29.14, 27.85, 27.46, 29.08, 29.81, 29.6, 29.81, 30.84, 31.06, 30.85, 31.42, 33.33, 35.31, 35.79, 35.02, 34.97, 34.28, 31.32, 29.17, 28.04, 27.88, 27.4, 26.94, 26.65, 28.04, 26.26, 27.0, 27.52, 28.69, 26.48, 29.11, 27.43], [28.39, 29.98, 28.63, 30.24, 29.74, 31.08, 30.69, 32.56, 31.73, 32.92, 33.98, 35.78, 37.27, 37.24, 34.64, 34.68, 31.05, 30.51, 27.87, 28.39, 27.47, 27.25, 26.77, 27.03, 27.35, 27.8, 26.97, 27.01, 28.01, 27.72, 28.14, 27.65], [28.56, 27.73, 27.28, 28.96, 30.12, 30.61, 30.59, 31.4, 32.48, 33.13, 34.66, 35.5, 37.22, 35.98, 34.05, 33.62, 30.55, 29.06, 26.85, 28.27, 28.12, 27.3, 26.88, 27.27, 27.29, 27.05, 26.68, 27.68, 28.54, 26.73, 28.3, 28.26], [26.91, 29.41, 28.32, 30.73, 30.03, 31.69, 30.61, 32.32, 33.96, 35.19, 34.99, 35.57, 32.66, 32.35, 30.24, 30.52, 29.48, 29.76, 28.47, 28.16, 27.77, 27.39, 26.76, 26.9, 27.63, 27.44, 27.35, 27.19, 28.53, 27.01, 27.99, 27.71], [26.59, 27.26, 28.0, 30.73, 30.6, 29.04, 29.67, 31.94, 34.14, 34.35, 33.86, 33.48, 30.28, 29.37, 28.19, 28.4, 29.51, 29.16, 28.5, 28.79, 27.94, 27.07, 27.04, 27.32, 28.19, 26.47, 27.31, 27.88, 28.8, 27.63, 28.16, 27.44], [27.58, 30.22, 29.24, 31.6, 29.55, 30.15, 29.5, 30.97, 31.97, 33.07, 29.15, 28.39, 27.08, 28.06, 26.65, 27.6, 28.1, 28.78, 28.29, 28.76, 28.07, 28.04, 27.43, 27.4, 27.86, 27.66, 27.65, 27.06, 28.15, 27.78, 28.24, 27.34], [26.83, 27.69, 28.15, 29.53, 29.36, 28.69, 28.8, 29.92, 30.3, 29.48, 26.68, 27.38, 27.0, 26.81, 27.0, 28.17, 28.57, 28.09, 28.12, 28.52, 27.82, 27.74, 27.42, 27.46, 28.51, 26.8, 27.65, 28.35, 28.83, 26.96, 28.15, 27.57], [28.59, 31.55, 27.83, 30.2, 28.52, 30.27, 27.92, 29.64, 27.01, 27.73, 25.77, 26.76, 27.91, 28.41, 27.72, 28.74, 27.74, 28.08, 27.19, 28.2, 27.52, 27.37, 27.38, 27.39, 27.01, 27.25, 27.56, 28.44, 27.83, 27.46, 28.65, 27.34], [28.03, 28.11, 26.34, 28.92, 27.94, 28.39, 26.22, 27.71, 26.55, 26.18, 26.0, 27.71, 28.28, 28.03, 27.84, 28.36, 27.79, 27.34, 27.06, 27.82, 28.23, 26.82, 27.7, 28.22, 28.58, 27.3, 27.78, 27.72, 28.86, 28.14, 28.49, 27.78], [27.24, 31.52, 26.88, 30.38, 26.61, 28.28, 25.13, 27.75, 26.71, 28.85, 27.26, 28.77, 27.97, 28.41, 27.18, 27.86, 27.02, 28.0, 26.91, 27.37, 27.42, 27.27, 27.64, 27.04, 27.99, 27.56, 28.31, 27.72, 28.55, 28.17, 28.56, 28.06], [25.06, 27.55, 24.84, 27.6, 25.77, 26.3, 25.23, 27.7, 26.91, 27.61, 26.62, 28.62, 27.64, 27.22, 26.12, 27.62, 27.98, 26.95, 26.85, 28.08, 27.88, 26.94, 26.97, 28.22, 28.72, 27.11, 28.4, 29.15, 28.67, 27.68, 28.49, 28.7], [23.62, 30.24, 23.86, 28.84, 25.4, 28.77, 26.39, 28.07, 26.93, 28.52, 26.41, 28.02, 25.95, 27.95, 26.14, 27.35, 27.2, 27.71, 27.19, 27.73, 27.76, 27.96, 27.16, 27.74, 27.67, 28.4, 28.38, 27.06, 27.59, 27.89, 28.86, 27.96], [20.86, 24.02, 23.41, 26.84, 25.17, 26.98, 25.42, 27.76, 27.22, 26.97, 26.15, 27.13, 26.57, 27.01, 26.2, 27.59, 27.48, 27.57, 27.7, 28.14, 28.63, 27.82, 27.43, 28.04, 28.13, 27.23, 27.96, 29.63, 29.26, 26.78, 28.47, 30.67], [22.27, 33.34, 25.12, 30.8, 26.14, 30.12, 25.95, 29.69, 26.25, 28.06, 25.81, 27.39, 26.59, 27.83, 26.06, 26.86, 27.49, 27.57, 27.32, 27.78, 28.36, 27.15, 27.58, 27.95, 28.15, 26.99, 28.67, 28.38, 28.13, 28.18, 30.37, 29.27], [19.7, 26.65, 22.4, 28.51, 26.01, 26.87, 24.29, 28.46, 27.08, 27.61, 25.68, 28.48, 27.52, 27.5, 26.72, 28.54, 28.3, 27.9, 27.84, 29.13, 29.12, 27.48, 28.24, 29.36, 29.93, 28.15, 28.17, 29.85, 30.66, 29.52, 30.69, 32.65]]

    
    flag_led = 0        #led补光灯状态标志
    flag_red = 0        #红外补光灯状态标志
    flag_uart = 0       #串口状态标志
    #global float_list 
    #flag_ddd = 0        #

    flag_RCXs = 0       #热成像使能标志位

    q = queue.Queue(maxsize=2)
    #热成像颜色条透明度
    alpha = 0.6  
        #热成像条透明度
    alphb = 0.3 

    # 配置并打开串口
    try:
        ser = serial.Serial(
            port='/dev/ttyUSB0',
            baudrate=500000,
            bytesize=serial.EIGHTBITS,
            parity=serial.PARITY_NONE,
            stopbits=serial.STOPBITS_ONE,
            timeout=1  # 设置读取超时时间
            )
    except serial.SerialException as e:
            print(f"打开串口失败: {e}")
            exit()

    def __init__(self, root):
        # 添加帧率计算相关变量
        self.frame_count = 0
        self.start_time = time.time()

        # 保存当前图像引用
        self.current_image = None  # 用于存储最新显示的PIL Image对象
        
        self.root = root
        self.root.title("OrangePi 热成像系统")
        self.root.geometry("1024x600")
        self.root.resizable(False, False)

        # 显示区域初始化
        self.left_frame = tk.Frame(root, bg="black")
        self.left_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
        self.display_label = tk.Label(self.left_frame)
        self.display_label.pack(fill=tk.BOTH, expand=True)

        # 右侧控制面板
        self.right_frame = tk.Frame(root, width=84, bg="#f0f0f0")
        self.right_frame.pack(side=tk.RIGHT, fill=tk.Y)
        
        # 功能按钮
        self.btn1 = self.create_button("摄像头模式", 0)
        self.btn2 = self.create_button("热成像模式", 1)
        self.btn3 = self.create_button("融合+模式", 2)
        self.btn4 = self.create_button("预留按钮", 3)
        self.btn5 = self.create_button("LED 补光", 4)
        self.btn6 = self.create_button("红外补光", 5)
        self.btn7 = self.create_button("保存截图", 6)
        self.btn8 = self.create_button("退    出", 7)


        # 硬件初始化
        self.current_mode = 3  # 0:摄像头 1:热成像
        self.init_camera()
        self.init_io()
        # 启动串口线程
        uart_thread = threading.Thread(target=self.uart_open)
        uart_thread.start()

        # uart_thread = threading.Thread(target=self.uart_open)
        # uart_thread.start()

    def get_fps(self):
        elapsed = time.time() - self.start_time
        return self.frame_count / elapsed if elapsed > 0 else 0

    def create_button(self, text, index):
        btn = tk.Button(
            self.right_frame,
            text=text,
            height=2, width=19,
            bg="#4a7a8c", fg="white",
            font=("Arial", 14),
            command=lambda: self.mode_switch(index)
        )
        btn.pack(pady=10, padx=5, fill=tk.X)
        return btn

    def init_io(self):
        wiringpi.wiringPiSetup()
        wiringpi.pinMode(19, GPIO.OUTPUT)
        wiringpi.pinMode(20, GPIO.OUTPUT)

    def init_camera(self):
        self.cap = cv2.VideoCapture(0)
        if not self.cap.isOpened():
            print("摄像头0 初始化失败 retry")
            self.cap = cv2.VideoCapture(1)
            if not self.cap.isOpened():
                print("摄像头1 初始化失败 end")

   
    def mode_switch(self, index):
        
        if index == 0:          # 切换回摄像头模式
            if self.current_mode != 0:
                self.current_mode = 0            
                self.update_camera()
            if self.flag_RCXs == 1:
                self.flag_RCXs = 0
            self.alpha = 0
            self.alphb = 0
        elif index == 1:        # 切换到热成像模式
            if self.flag_RCXs == 0:
                self.flag_RCXs = 1
            self.alpha = 0.9
            self.alphb = 0.9
        elif index == 2:        # 切换到融合模式
            if self.flag_RCXs == 0:
                self.flag_RCXs = 1
            self.alpha = 0.7
            self.alphb = 0.5
        elif index == 3:        #启动串口            
            # self.uart_switch()
            print("key3")
        elif index == 4:        #LED补光
            self.led_switch()
        elif index == 5:        #红外补光
            self.red_switch()
        elif index == 6:            
            self.save_screenshot()
        elif index == 7:
            self.uart_close()
            root.quit()


    def led_switch(self):
        global flag_led        
        if self.flag_led == 0:
            self.flag_led = 1
            wiringpi.digitalWrite(19, GPIO.HIGH)
        elif self.flag_led == 1:
            self.flag_led = 0
            wiringpi.digitalWrite(19, GPIO.LOW)

    def red_switch(self):
        global flag_red        
        if self.flag_red == 0:
            self.flag_red = 1
            wiringpi.digitalWrite(20, GPIO.HIGH)
        elif self.flag_red == 1:
            self.flag_red = 0
            wiringpi.digitalWrite(20, GPIO.LOW)

    def uart_switch(self):
        global flag_uart        
        if self.flag_uart == 0:
            self.flag_uart = 1
            uart_thread = threading.Thread(target=self.uart_open)
            uart_thread.start()
            # uart_thread.join()
            
            #self.uart_open()
        elif self.flag_uart== 1:
            self.flag_uart = 0
            
            #self.uart_close()

    def save_screenshot(self):
        """保存当前显示的图像"""
        if self.current_image is None:
            # self.show_status("无可用图像可保存", "red")
            print("无可用图像可保存")
            messagebox.showinfo("提示消息",f"无可用图像可保存")
            return
        
        # 创建保存目录
        save_dir = os.path.expanduser("/home/orangepi/ovs_save")
        os.makedirs(save_dir, exist_ok=True)
        
        # 生成文件名
        timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
        filename = f"ovs_{timestamp}.png"
        save_path = os.path.join(save_dir, filename)
        
        try:
            # 保存为PNG格式（保留透明度）
            self.current_image.save(save_path, "PNG")
            print("Save Succ")
            messagebox.showinfo("提示消息",f"截图已保存至: {save_path}")
            # self.show_status(f"截图已保存至: {save_path}", "green")
        except Exception as e:
            # self.show_status(f"保存失败: {str(e)}", "red")
            print("Save Fail")
            messagebox.showinfo("提示消息",f"保存失败: {str(e)}")
    
    # def show_status(self, message, color):
    #     """显示状态信息"""
    #     self.status_label.config(text=message, fg=color)
    #     self.root.after(3000, lambda: self.status_label.config(text=""))

    def update_camera(self):
        global matrix
        global alpha
        global alphb
        global pil_img
        #图像分辨率
        cam_x = 800
        cam_y = 600

        rcx_x = 800
        rcx_y = 600

        #定义字体绝对路径
        font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"  # 系统字体
        if not os.path.exists(font_path):
            font_path = ImageFont.load_default().path

        #从队列读取热成像数据
        if not self.q.empty():
            self.matrix = self.q.get()
            print("Get new one")
        else:
            print("No new one")
        
        #
        if self.current_mode == 0:
            ret, frame = self.cap.read()
            if ret:
                # 转换颜色空间
                img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
                pil_img = Image.fromarray(img).resize((cam_x, cam_y),Image.LANCZOS)
                
                # 创建绘图对象
                draw = ImageDraw.Draw(pil_img)

                
                
                
            if self.flag_RCXs == 1:

                
                # 寻找温度极值坐标
                my_matrix = np.array(self.matrix)
                my_matrix = my_matrix[:,::-1]     #逆序每一行的数据
                max_coords = np.unravel_index(np.argmax(my_matrix), my_matrix.shape)
                min_coords = np.unravel_index(np.argmin(my_matrix), my_matrix.shape)
                # 数据归一化（自动适应温度范围）
                norm = plt.Normalize(vmin=np.min(my_matrix), vmax=np.max(my_matrix))
                
                # 应用inferno颜色映射
                cmap = cm.get_cmap('inferno')
                colored = cmap(norm(my_matrix))[:, :, :3]  # 忽略alpha通道
                
                # 提升分辨率 (24x32 -> 480x640)
                thermal_img = Image.fromarray((colored * 255).astype(np.uint8))
                # thermal_img = thermal_img.resize((480, 360), Image.BICUBIC)
                thermal_img = thermal_img.resize((rcx_x, rcx_y), Image.BICUBIC)
                # 第二个参数：
                # Image.NEAREST ：低质量
                # Image.BILINEAR：双线性
                # Image.BICUBIC ：三次样条插值
                # Image.ANTIALIAS：高质量
                
                # 创建透明层
                overlay = Image.new('RGBA', pil_img.size, (0,0,0,0))
                
                # 计算居中位置
                x_offset = (pil_img.width - thermal_img.width) // 2  # (800-480)/2=160
                y_offset = (pil_img.height - thermal_img.height) // 2  # (640-360)/2=140
                
                # 叠加热力图
                overlay.paste(thermal_img.convert('RGBA'), (x_offset, y_offset))
                
                # 转换极值坐标到显示坐标系
                
                chazhi_beishu = cam_x / 32
                
                #测试 画线
                
                
                
                
                
                # 应用透明度
                overlay = overlay.convert('RGBA')
                overlay.putalpha(int(255 * self.alphb))  #透明系数：0.3

                
                
                #添加颜色条显示
                draw = ImageDraw.Draw(overlay)
                colorbar_width = 20
                colorbar_height = cam_y-40
                for i in range(colorbar_height):
                    color = cmap(i/colorbar_height)
                    draw.rectangle(
                        [(pil_img.width - 10 - colorbar_width, 20 + i),
                        (pil_img.width - 10, 20 + i + 1)],
                        fill=(int(color[0]*255), int(color[1]*255), int(color[2]*255), int(self.alpha*255))
                    )
                # 绘制温度极值标记
                # 加载字体（推荐使用绝对路径）
                font = ImageFont.truetype(font_path, 16)

                # 最高温度红色"+"标记
                draw.text((max_coords[1]*chazhi_beishu, max_coords[0]*chazhi_beishu), "+", font=font, fill=(255,0,0,200))
                max_temp = my_matrix[max_coords]
                draw.text((max_coords[1]*chazhi_beishu+30, max_coords[0]*chazhi_beishu), 
                        f"{max_temp:.1f}℃", font=font, fill=(255,0,0,200))
                # 最低温度白色"+"标记
                draw.text((min_coords[1]*chazhi_beishu, min_coords[0]*chazhi_beishu),"+", font=font, fill=(255,255,255,200))
                min_temp = my_matrix[min_coords]
                draw.text((min_coords[1]*chazhi_beishu+30, min_coords[0]*chazhi_beishu), 
                        f"{min_temp:.1f}℃", font=font, fill=(255,255,255,200))
                
                # 加载字体（推荐使用绝对路径）                
                font = ImageFont.truetype(font_path, 24)             
                
                # 要显示的文字内容
                text_content = [
                    {"text": f"FPS: {self.get_fps():.1f}", "pos": (10, 10), "color": (255, 255, 255)}
                ]
                
                # 添加文字描边效果
                for text_info in text_content:
                    text = text_info["text"]
                    x, y = text_info["pos"]
                    # 先绘制黑色描边
                    for dx in [-1, 0, 1]:
                        for dy in [-1, 0, 1]:
                            if dx != 0 or dy != 0:
                                draw.text((x+dx, y+dy), text, font=font, fill=(0,0,0))
                    # 再绘制主体文字
                    draw.text((x, y), text, font=font, fill=text_info["color"])
                
                # 合并图像
                pil_img=Image.alpha_composite(pil_img.convert('RGBA'), overlay).convert('RGB')

            """更新显示并保存当前图像引用"""
            self.current_image = pil_img.copy()  # 保存当前图像的副本
            # 转换为Tkinter兼容格式
            imgtk = ImageTk.PhotoImage(image=pil_img)
            # 更新显示
            self.display_label.imgtk = imgtk
            self.display_label.configure(image=imgtk)
            self.display_label.place(x=0,y=0)
            # 保持刷新循环  
            self.root.after(30, self.update_camera)
            # 在函数末尾添加
            self.frame_count += 1
            if self.frame_count % 30 == 0:  # 每30帧重置计数器
                self.frame_count = 0
                self.start_time = time.time()

    def update_thermal(self):
        temp = 3



    def uart_open(self):
        buffer = bytearray()
        #global float_list
        try:
            while True:
                
                # 读取可用数据
                data = self.ser.read(self.ser.in_waiting or 1)
                if data:
                    buffer.extend(data)
                    # 查找开始和结束标记
                    start_idx = buffer.find(b'SSS ')
                    while start_idx != -1:
                        # 在剩余数据中查找结束标记
                        end_idx = buffer.find(b' EEE', start_idx + 2)
                        if end_idx == -1:
                            break  # 没有找到结束标记，继续读取

                        # 提取数据部分
                        data_part = buffer[start_idx + 4 : end_idx]
                        # 移除已处理的数据（包括结束标记）
                        del buffer[:end_idx + 4]
                        
                        try:
                            # 转换为字符串并分割
                            #print(data_part[1])
                            data_str = data_part.decode('utf-8')
                            numbers = data_str.split()

                            # 确保数据长度正确
                            assert len(numbers) == 768, "数据必须包含768个浮点数"

                            # 转换为浮点数列表
                            float_list = [float(num) for num in numbers]

                            #print(float_list)

                            # 构建32x24的矩阵
                            xmatrix = [float_list[i*32 : (i+1)*32] for i in range(24)]

                            if not self.q.full():
                                self.q.put(xmatrix)
                            else:
                                xxx=self.q.get()
                                self.q.put(xmatrix)
                            print(self.q.qsize())
                            #print(xmatrix)
                            # 输出前几行验证（可选）
                            

                            #print("矩阵前两行示例：")
                            #for row in xmatrix[:1]:
                            #    print(row)
                            
                        
                            

                        except UnicodeDecodeError:
                            print("解码错误：数据包含非ASCII字符")
                        except ValueError:
                            print("数据转换错误：包含无效浮点数")
                        except Exception as e:
                            print(f"处理数据时发生错误: {e}")

                        # 继续查找下一个数据包
                        
                        start_idx = buffer.find(b'SSS ')

        except KeyboardInterrupt:
            print("程序被用户中断")
        finally:
            self.ser.close()
            print("串口已关闭")

    def uart_close(self):
        self.ser.close()
        print("串口已关闭")

    def __del__(self):
        if hasattr(self, 'cap'):
            self.cap.release()

if __name__ == "__main__":
    root = tk.Tk()
    app = ThermalImagingApp(root)
    # root.attributes('-fullscreen',True)
    root.mainloop()


'''
# 创建一个信息弹窗
messagebox.showinfo("Title", "This is an information message.")
 
# 创建一个警告弹窗
messagebox.showwarning("Warning", "This is a warning message.")
 
# 创建一个错误弹窗
messagebox.showerror("Error", "This is an error message.")
 
# 创建一个询问弹窗并获取用户响应
response = messagebox.askquestion("Question", "Do you want to continue?")
if response == 'yes':
    print("User chose 'Yes'")
else:
    print("User chose 'No'")

# 创建一个输入对话框获取字符串输入
user_input = simpledialog.askstring("Input", "Please enter your name:")
if user_input:
    print(f"Hello, {user_input}!")
 
'''